package edu.hebeu;

import android.content.Intent;
import android.widget.RelativeLayout;

import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

import edu.hebeu.activity.BaseActivity;
import edu.hebeu.activity.HomeActivity;

public class MainActivity extends BaseActivity {

    private RelativeLayout rl_main;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initViews() {
        rl_main = (RelativeLayout) findViewById(R.id.rl_main);
        Random random = new Random();
        int i = random.nextInt(4);

        if (i == 0) {
            rl_main.setBackgroundResource(R.drawable.main_bg1);
        } else if (i == 1) {
            rl_main.setBackgroundResource(R.drawable.main_bg2);
        } else if (i == 2) {
            rl_main.setBackgroundResource(R.drawable.main_bg3);
        } else if (i == 3) {
            rl_main.setBackgroundResource(R.drawable.main_bg4);
        }

        Timer timer = new Timer();
        TimerTask task = new TimerTask() { // 创建task任务对象实例
            @Override
            public void run() {
                // 跳转到游戏主界面
                startActivity(new Intent(MainActivity.this, HomeActivity.class));
                finish();
            }
        };

        // 通过Timer对象设置任务，如下，即表示5000毫秒后开始任务
        timer.schedule(task, 5000);
    }
}
